package com.hrt.web.mailRecord.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hrt.base.BaseController;
import com.hrt.bean.MailRecord;
import com.hrt.util.RamUtil;
import com.hrt.web.mailRecord.service.MailRecordService;
@Controller
@RequestMapping("HRTWEB/mailRecord")
public class MailRecordController extends BaseController<MailRecord>{
	@Autowired
	private MailRecordService mailRecordService;
	
	/**
	 * @param mail
	 * @param memberId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/save")
	@ResponseBody
	public String save(@RequestParam(value = "mail", required = true) String mail,
			@RequestParam(value = "memberId", required = true) Long memberId,
			HttpServletRequest request, HttpServletResponse response) {
		MailRecord mailRecord = new MailRecord();
		String code = RamUtil.getMobileVaildCode();//随机生成邮箱验证码
		
		String content = "恩人13694266240你好,你的邮箱验证码为"+code+"感谢你对何人堂创意产品网的支持,请继续关注http://www.who158.com";
		mailRecord.setVaildCode(code);//邮箱验证码
		mailRecord.setSendTime(mailRecordService.getDate());//发送时间
		mailRecord.setMail(mail);//邮件
//		smsRecord.setBusType(newBusType);//业务类型
		mailRecord.setContent(content);//短信内容
		if(memberId!=-1){
			mailRecord.setMemberId(memberId);//用户id
			
		}
		mailRecord.setStatus(0);//验证码状态
		mailRecord.setIsdelete(0);//是否删除
	try {
		
		mailRecordService.saveMailRecord(mailRecord);
		mailRecordService.sendMail(mail, code);
			//SMSSender.sendSMS(content, mobile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
		
	}
}
